library(tidyverse)
library(readxl)
path <- "Excel/800-899/883/883 Regex Extraction.xlsx"
input <- read_excel(path, range = "A2:A41")
test <- read_excel(path, range = "C2:E41")
result = input %>%
mutate(
`IP Address` = str_extract(
`Server Dump Data`,
"\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
),
`Ticket ID` = str_extract(`Server Dump Data`, "TKT-\\d{5}"),
Latency = map_chr(
str_extract_all(`Server Dump Data`, "\\d+(?=\\s?ms)"),
~ tail(.x, 1)
) %>%
as.numeric()
) %>%
select(-`Server Dump Data`)
all.equal(result, test)
# [1] TRUEExcel BI - Excel Challenge 883
excel-challenges
excel-formulas
🔰 Extract following

Challenge Description
🔰 Extract following
Solutions
- Logic: Read the workbook ranges needed for the challenge; Derive the required intermediate columns; Parse the packed text or string structure.
- Strengths: The solution stays close to the text pattern itself, which makes the extraction logic easy to audit.
- Areas for Improvement: The solution assumes the workbook layout and selected ranges remain stable, so any structural change in the sheet would require small adjustments.
- Gem: A small number of well-targeted text patterns does most of the heavy lifting.
import pandas as pd
import re
path = "Excel/800-899/883/883 Regex Extraction.xlsx"
input = pd.read_excel(path, usecols=[0], skiprows=1, nrows=39)
test = pd.read_excel(path, usecols=[2,3,4], skiprows=1, nrows=39)
result = input.copy()
IP_PATTERN = r"\d{1,3}(?:\.\d{1,3}){3}"
TICKET_PATTERN = r"TKT-\d{5}"
LATENCY_PATTERN = r"\d+(?=\s?ms)"
def extract_pattern(s, pattern, n=1, last=False):
matches = re.findall(pattern, str(s))
if not matches:
return None
if last:
return int(matches[-1])
if n == 1:
return matches[0]
return matches[:n]
result["IP Address"] = result["Server Dump Data"].apply(lambda s: extract_pattern(s, IP_PATTERN))
result["Ticket ID"] = result["Server Dump Data"].apply(lambda s: extract_pattern(s, TICKET_PATTERN))
result["Latency"] = result["Server Dump Data"].apply(lambda s: extract_pattern(s, LATENCY_PATTERN, last=True))
result = result.iloc[:, 1:]
print(result.equals(test)) # TrueThe Python version expresses the core extraction rule directly and keeps the pattern matching easy to review.
Difficulty Level
Medium
The individual steps are manageable, but the correct transformation pattern is not obvious from the raw data.